package start.threadlocal;


public class UserContext {
    public static ThreadLocal<Long> userIdLocal = new ThreadLocal();
    public static ThreadLocal<String> userLoginLocal = new ThreadLocal();
    public static ThreadLocal<String> userNameLocal = new ThreadLocal();
    public static ThreadLocal<Long> appSystemIdLocal = new ThreadLocal();

    public UserContext() {
    }

    public static void setCurrentUserId(Long userId) {
        userIdLocal.set(userId);
    }

    public static void setCurrentUserLoginName(String loginName) {
        userLoginLocal.set(loginName);
    }

    public static void setCurrentUserName(String userName) {
        userNameLocal.set(userName);
    }

    public static Long getCurrentUserId() {
        Long id = -1L;

        try {
            if (userIdLocal.get() != null) {
                id = (Long)userIdLocal.get();
            }
        } catch (Exception var3) {
            if (userIdLocal.get() != null) {
                id = (Long)userIdLocal.get();
            }
        }

        return id;
    }

    public static String getCurrentUserLoginName() {
        String loginName = "";

        try {
            if (userLoginLocal.get() != null) {
                loginName = (String)userLoginLocal.get();
            }
        } catch (Exception var3) {
            if (userLoginLocal.get() != null) {
                loginName = (String)userLoginLocal.get();
            }
        }

        return loginName;
    }

    public static String getCurrentUserName() {
        String userName = "";
        try {
            if (userNameLocal.get() != null) {
                userName = (String)userNameLocal.get();
            }
            return userName;
        } catch (Exception var3) {
            if (userNameLocal.get() != null) {
                userName = (String)userNameLocal.get();
            }

            return userName;
        }
    }

    public static void removeContext() {
        userIdLocal.remove();
        userNameLocal.remove();
        userLoginLocal.remove();
        appSystemIdLocal.remove();
    }

    public static void setAppSystemId(Long userId) {
        appSystemIdLocal.set(userId);
    }

    public static Long getAppSystemId() {
        Long appSystemId = -1L;

        try {
            if (appSystemIdLocal.get() != null) {
                appSystemId = (Long)appSystemIdLocal.get();
            }
        } catch (Exception var2) {
            if (appSystemIdLocal.get() != null) {
                appSystemId = (Long)appSystemIdLocal.get();
            }
        }

        return appSystemId;
    }
}